import db from '~~/DB';
import { defineResponseResolver } from '~~/mocks/define';

export default defineResponseResolver(async (req, res, ctx) => {
  // const menus = await db.dicts.toCollection().sortBy('sort');

  const dict = await db.dicts.get({ key: req.params.key });
  if (!dict) {
    return res(ctx.status(404), ctx.json({ message: '资源不存在' }));
  }

  const children = await db.dicts
    .where({ parent: req.params.key })
    .sortBy('sort');

  dict.children = children;

  return res(ctx.json(dict));
});
